//
//  SYYueJuanHtmlTableViewCell.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/6/5.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYYueJuanHtmlTableViewCell.h"



@interface SYYueJuanHtmlTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *tableView;
@property (weak, nonatomic) IBOutlet UIWebView *webView;


@end


@implementation SYYueJuanHtmlTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.webView.opaque = NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setHtmlStr:(NSString *)htmlStr {
//    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
//    NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:bundlePath];
//    NSDictionary *dict = infoDict[@"details"];
//    htmlStr = dict[@"key"]; http://webeditor.mykeyu.cn
    CGFloat width = self.frame.size.width-30;
    htmlStr = [htmlStr stringByReplacingOccurrencesOfString:@"src=\"" withString:@"src=\"http://webeditor.31waiyu.com"];
    
    NSString *str = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto}</style></head>%@",width,htmlStr];
    
    [self.webView loadHTMLString:str baseURL:nil];
    
    if (htmlStr.length > 0) {
        self.webView.hidden = NO;
    } else {
        self.webView.hidden = YES;
    }
}


- (void)setYjstModel:(SYYueJuanShiTiModel *)yjstModel {
    _yjstModel = yjstModel;
    
    NSString *htmlStr = yjstModel.rightAnswerContent;
//    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
//    NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:bundlePath];
//    NSDictionary *dict = infoDict[@"details"];
//    htmlStr = dict[@"key"];
    CGFloat width = self.frame.size.width-30;
    CGFloat areawidth = [yjstModel.areaWidth floatValue];
    CGFloat mrWidth ;
    if (width < areawidth) {
        mrWidth = width;
    } else {
        mrWidth = areawidth;
    }
    
    
    htmlStr = [htmlStr stringByReplacingOccurrencesOfString:@"src=\"" withString:@"src=\"http://webeditor.31waiyu.com"];
    
    NSString *str = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto}</style></head>%@",mrWidth,htmlStr];
    
    [self.webView loadHTMLString:str baseURL:nil];
    
}




@end














